<?php

/**
 * Created by PhpStorm.
 * User: feng
 * Date: 2017/1/21
 * Time: 下午10:08
 */
class Lyw_gaofei_record_model extends CI_Model
{
    public function __construct()
    {
        $this->load->database();
    }

    public function getListJson()
    {
        $sql = "select a.* , b.username from lyw_gaofei_record as a left join lyw_user as b on a.translation_user_id = b.id;";
        $list = $this->db->query($sql)->result_array();
        return $list;
    }

    public function getSum()
    {
        $sql = "select sum(money) as sum from lyw_gaofei_record";
        $row = $this->db->query($sql)->row();
        if (empty($row->sum)) {
            return 0;
        } else {
            return $row->sum;
        }
    }

    public function insert($manager_id, $translation_user_id, $text_number, $score, $read_number, $level, $money)
    {
        $data = array('manager_id' => $manager_id, 'translation_user_id' => $translation_user_id, 'text_number' => $text_number, 'score' => $score, 'read_number' => $read_number,
            'level' => $level, 'money' => $money, 'creat_time' => time());
        $str = $this->db->insert_string('lyw_gaofei_record', $data);
        $this->db->query($str);
        return $this->db->insert_id();
    }

    public function getListByUserId($user_id)
    {
        $sql = 'select * from lyw_gaofei_record where translation_user_id = ? and money > 0 order by id desc limit 0 , 5';
        $list = $this->db->query($sql, array($user_id))->result_array();
        return $list;
    }
}